The best answer is: buy a compiler that supports templates. When this is not feasible, the next best answer is to buy or build a template preprocessor (ex: reads C++-with-templates, outputs C++-with-expanded-template-classes; such a system needn't be perfect; it cost my company about three man-weeks to develop such a preprocessor). If neither of these is feasible, you can use the macro preprocessor to fake templates. But beware: it's tedious; templates are a better solution wrt development and maintenance costs.
Here's how you'd declare my 'Vec' example from above. First we define 'Vec(T)' to concatenate the name 'Vec' with that of the type T (ex: Vec(String) becomes 'VecString'). This would go into a header file such as Vec.h:
#include <generic.h> //to get the 'name2()' macro
#define Vec(T) name2(Vec,T)
Next we declare the class Vec(T) using the name 'Vecdeclare(T)' (in general you would postfix the name of the class with 'declare', such as 'Listdeclare' etc):
#define Vecdeclare(T) \
class Vec(T) { \
int xlen; \
T* xdata; \
int check(int i); /*return i if in bounds else throw*/ \
Note that types whose names are other than a single identifier do not work properly. Ex: Vec(char*) creates a class whose name is 'Vecchar*'. The patch is to create a typedef for the appropriate type:
#include "Vec.h"
typedef char* charP;
declare(Vec,charP)
It is important that every declaration of what amounts to 'Vec<char*>' must all use exactly the same typedef, otherwise you will end up with several equivalent classes, and you'll have unnecessary code duplication. This is the sort of tedium which a template mechanism can handle for you.